<template>
	<view class="sumit">
		<textarea class="text" @input="input" maxlength="100" placeholder="请输入您的评论" />
		<view class="btn" @tap="submit()">立即发布</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			value: ''
		};
	},
	onLoad(option){
		this.type = option.type;
		this.goodsid = option.goodsid;
	},
	methods: {
		input(e) {
			this.value = e.detail.value;
		},
		async submit() {
			let authData = uni.getStorageSync('authData');
			if (!authData.auth) {
				uni.showToast({
					title: '请先登录',
					icon: 'none',
					duration: 2000
				});
				setTimeout(function() {
					uni.navigateTo({
						url: '/pages/login/login'
					});
				}, 2000);
				return false;
			}
			if (!this.value) {
				uni.showToast({
					title: '评论内容不能为空',
					icon: 'none',
					duration: 2000
				});
				return true;
			}
			let $res = await this.$request.post('/landed/addComment', {
				data: {
					content: this.value,
					goodsid: this.goodsid,
					type:this.type
				}
			});
			uni.showToast({
				title: '评论成功。',
				icon: 'none',
				duration: 2000
			});
			this.value = '';
			uni.navigateBack({
				delta:1
			});
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: #efefef;
}
.sumit {
	background-color: #efefef;
	width: 100%;
	height: 100%;
}
.text {
	background-color: #ffffff;
	height: 500upx;
	width: 100%;
	box-sizing: border-box;
	padding: 20upx;
	font-size: $uni-font-size-base;
}
.btn {
	width: 600upx;
	margin: 0 auto;
	margin-top: 150upx;
	height: 100upx;
	line-height: 100upx;
	border-radius: 50upx;
	text-align: center;
	font-size: $uni-font-size-lg;
	color: #fff;
	background: linear-gradient(left, #ff5d42, #f33632);
}
</style>
